#! /usr/bin/env python
# encoding: utf-8

import glob
import os
import ntpath
import sys

def run_test(ctx):
    sys.path.append(ctx.top_dir)
    import waf_tools

    waf_tools.run_tests(ctx)

def configure(cfg):
    #system lib
    cfg.env.append_value('LIB',['ssl','crypto','dl','z'])
    #boost lib
    
    cfg.env.DEFINES_BOOST     = ['BOOST']
    cfg.env.LIB_BOOST         = ['boost_system', 'boost_thread', 'boost_filesystem', 'boost_date_time']
    cfg.env.LIBPATH_BOOST     = ['/export/boost/105500/libs/']
    cfg.env.INCLUDES_BOOST    = ['/export/boost/105500/include/']

    cfg.env.DEFINES_MARIADB   = ['MARIADB']
    cfg.env.STLIB_MARIADB     = ['mariadbclient']
    cfg.env.STLIBPATH_MARIADB = ['/export/mariadb/libs/']
    cfg.env.INCLUDES_MARIADB  = ['/export/mariadb/include/']
    
    cfg.env.DEFINES_GTEST     = ['GTEST']
    cfg.env.STLIB_GTEST       = ['gtest']
    cfg.env.STLIBPATH_GTEST   = ['/export/gtest/libs/']
    cfg.env.INCLUDES_GTEST    = ['/export/gtest/include/']
    

def build(bld):
    
    sys.path.append(bld.top_dir)
    import waf_tools

    IncludePaths = waf_tools.get_module_include_dirs(bld,'common')
    IncludePaths.append('include')

    #Build the static library
    # find all .cpp files ( exclude unit tests )
    sources_files =  bld.path.ant_glob('**/*.cpp',excl=['**/test_*.cpp'])
    bld.stlib( source = sources_files, target="common", use="MARIADB BOOST", includes=IncludePaths )
    
    #Unit test related stuff
    
    if bld.env.with_unittest:
        waf_tools.build_tests(bld, "common MARIADB GTEST", IncludePaths)
